package com.greenbook.controller.user;

import com.greenbook.dto.UserInfoDTO;
import com.greenbook.dto.UserLoginDTO;
import com.greenbook.result.Result;
import com.greenbook.service.UserService;
import com.greenbook.vo.UserInfoVO;
import com.greenbook.vo.UserLoginVO;
import io.jsonwebtoken.security.Request;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "用户登录接口")
@Slf4j
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    /**
     * 用户登录
     *
     * @param userLoginDTO 用户登录信息
     * @return 用户登录信息
     */
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户登录:{}", userLoginDTO);
        return Result.success(userService.login(userLoginDTO));
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/info/{userId}")
    @Operation(summary = "获取用户信息")
    public Result<UserInfoVO> getUserInfo(@PathVariable Long userId) {
        log.info("获取用户信息:{}", userId);
        return Result.success(userService.getUserInfo(userId));
    }

    @PutMapping("/info")
    @Operation(summary = "更新用户信息")
    public Result updateUserInfo(@RequestBody UserInfoDTO userInfoDTO) {
        log.info("更新用户信息:{}", userInfoDTO);
        userService.updateUserInfo(userInfoDTO);
        return Result.success();
    }
    /**
     * 退出登录
     * @return
     */
    @GetMapping("/logout/{userId}")
    @Operation(summary = "退出登录")
    public Result logout(@PathVariable Long userId) {
        log.info("退出登录:{}", userId);
        return Result.success();
    }
}
